<?php
$pageTitle = "Role Management";
include "common/header.php";
include "config.php";
include "src/role/role.class.php";
include "src/role/controller.class.php";
if (Security::isCurrentUserGrantedWith("ROLE_ADMIN")){
if (isset($_REQUEST['action'])){
	$action = $_REQUEST['action'];
}else {
	$action = $_POST['action'];
}

if (isset($action)){		
	switch ($action){
		case "new":{
			include("src/role/form.php");	
			break;
		}
		case "update":{
			if (isset($_REQUEST['id'])){
				$id = $_REQUEST['id'];
				include("src/role/form.php");	
			}else {
				$id = $_POST['id'];
			}
			break;
		}
		case "delete":{
			if (isset($_REQUEST['id'])){
				if ($_REQUEST['id'] == "ROLE_ADMIN" || $_REQUEST['id'] == "ROLE_CUSTOMER"){
					$strRole = $_REQUEST['id'];
					header("Location: ../$www/index_role.php?action=new&msg=err&role=$strRole");
				}else{
					$strRole = $_REQUEST['id'];
					RoleController::delete($_REQUEST['id']);
					header("Location: ../$www/index_role.php?action=new&msg=inf&role=$strRole");
				}
			}
			break;
		}
	}
}	

include "src/role/list.php" ;
}else{
include("common/denied.php");	
}
include "common/footer.php";
?>